Skip to content

Use module-qualified imports for storage.memory.semrefindex - #303

Merged
Bernhard Merkle (bmerkle) merged 2 commits into
microsoft:mainfrom
bmerkle:fix-import-style-semrefindex
Sep 28, 2026
Merged

Bernhard Merkle (bmerkle) merged 2 commits into
microsoft:mainfrom
bmerkle:fix-import-style-semrefindex

Conversation

@bmerkle

Copy link
Copy Markdown
Collaborator

Summary

Test plan

  • make (format, check on 3.12/3.14, test, build) — 0 pyright errors, 737 passed / 12 skipped, wheel builds

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR completes Phase 2 of the import-style standardization effort (#298) by switching remaining low-frequency call sites of the in-memory storage.memory.semrefindex module from direct-symbol imports to module-qualified usage, aligning src/typeagent with the established pattern already used in knowpro/conversation_base.py.

Changes:

  • Replace direct function imports (collect_action_terms, collect_entity_terms) with semrefindex.<fn> calls in the add-messages pipeline.
  • Replace direct class import (TermToSemanticRefIndex) with semrefindex.TermToSemanticRefIndex in MCP server typing and in-memory storage provider.
  • Keep sqlite semrefindex direct-symbol imports unchanged (single-class export, already consistent).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/typeagent/storage/memory/provider.py Imports semrefindex as a module and qualifies the TermToSemanticRefIndex type/constructor usage.
src/typeagent/mcp/server.py Switches to module import (semrefindex) and updates the QueryEvalContext type parameter accordingly.
src/typeagent/knowpro/add_messages.py Switches to module import (semrefindex) and qualifies calls to term-collection helpers.

@bmerkle

Copy link
Copy Markdown
Collaborator Author

robgruen would you mind taking a look at this one when you get a chance? Thanks!

semrefindex (memory variant) is overwhelmingly function-oriented (18
functions + 1 class), so per AGENTS.md's import style guidelines it
defaults to module-qualified. Converts the remaining low-frequency
direct-symbol call sites:

- knowpro/add_messages.py: collect_action_terms, collect_entity_terms
- mcp/server.py: TermToSemanticRefIndex
- storage/memory/provider.py: TermToSemanticRefIndex

conversation_base.py already used `from ..storage.memory import
semrefindex` + qualified calls, so no change needed there.

The sqlite variant's own class (SqliteTermToSemanticRefIndex) exports
a single class and is left as direct-symbol import, already
compliant.

Scope: src/typeagent only, per microsoft#298.

Phase 2 (3/3) of the import-consistency cleanup tracked in microsoft#298.
@bmerkle

Copy link
Copy Markdown
Collaborator Author

robgruen rebased onto main and resolved the conflict in storage/memory/provider.py (merged with #301's reltermsindex qualification). make passes (0 pyright errors, 756 tests, build OK). Ready for your review.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@bmerkle
Bernhard Merkle (bmerkle) merged commit 223ae53 into microsoft:main Sep 28, 2026
21 checks passed
Bernhard Merkle (bmerkle) added a commit that referenced this pull request Oct 10, 2026
PR 6 of the #307 rename series.

**Renames**
- `storage/memory/semrefindex.py` →
`storage/memory/semantic_ref_index.py`
- `storage/sqlite/semrefindex.py` →
`storage/sqlite/semantic_ref_index.py`
- `tests/test_semrefindex.py` → `tests/test_semantic_ref_index.py`
- `tests/test_memory_semrefindex.py` →
`tests/test_memory_semantic_ref_index.py`

Module-qualified call sites (`semrefindex.X`, from #303) now use
`semantic_ref_index.X`. References in `docs/spec/` are updated. Files
moved with `git mv` to keep history.

**One non-mechanical change: a name clash on Python 3.14+**

`MemoryStorageProvider` has a `semantic_ref_index` property, and also a
class-level annotation `_conversation_index:
semantic_ref_index.TermToSemanticRefIndex`. With the module renamed, on
Python 3.14+ (where annotations are evaluated lazily, in the class
namespace) the property shadows the module, so
`MemoryStorageProvider.__annotations__` raises:

```
AttributeError: 'property' object has no attribute 'TermToSemanticRefIndex'
```

Python 3.12 evaluates the annotation eagerly before the property exists,
so it's unaffected. None of the existing tests touch `__annotations__`,
so CI didn't catch it. Fix: `memory/provider.py` imports the class
directly (`from .semantic_ref_index import TermToSemanticRefIndex`),
which AGENTS.md allows for classes.

To catch this kind of clash (the remaining renames in #307 may hit it
too), the PR adds `tests/test_class_annotations.py`, which evaluates
`__annotations__` for every class in all 68 modules of the package
(walking the files, since most subpackages are namespace packages that
`pkgutil.walk_packages` skips). I checked that it fails on 3.14 without
the fix and passes with it.

No compatibility aliases (decided in #307); added to the `0.6.0
(unreleased)` → "Breaking changes" list in `CHANGELOG.md`.

**Testing:** full `make` passes (format, ruff, pyright, 784 passed / 12
skipped, build).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@bmerkle
Bernhard Merkle (bmerkle) deleted the fix-import-style-semrefindex branch October 25, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants